package com.zhiyou100.entity;

import jdk.nashorn.internal.objects.annotations.Constructor;
import lombok.*;

import javax.persistence.*;
import java.io.Serializable;

/**
 * Entity 指定读取实体类
 * Table(name = "tab_worker") 指定对应的表
 *
 * @author yang
 */
@Entity
@Table(name = "tab_worker")
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Builder
public class Worker implements Serializable {
    /**
     * Id 指定当前的属性是 主键列
     * GeneratedValue(strategy = GenerationType.IDENTITY)  默认是自动，等价于 native
     * Column(name = "w_id") 指定此此属性对应的列
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "w_id")
    private Integer wid;

    @Column(name = "w_name")
    private String wname;

    @Column(name = "w_salary")
    private Float wsalary;

    /**
     * ManyToOne(targetEntity = Company.class) 指定 多对一的实体类
     * JoinColumn(name = "company_id") 注释的是另一个表指向本表的外键。
     */
    @ManyToOne(targetEntity = Company.class)
    @JoinColumn(name = "company_id")
    private Company company;

    @Override
    public String toString() {
        return "Worker{" +
                "wid=" + wid +
                ", wname='" + wname + '\'' +
                ", wsalary=" + wsalary +
                '}';
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        return super.equals(obj);
    }
}
